package com.mofeng.myshop.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mofeng.myshop.domain.dto.CarmineDto;
import com.mofeng.myshop.domain.dto.search.CarmineQo;
import com.mofeng.myshop.domain.po.Carmine;
import com.mofeng.myshop.service.CarmineService;
import com.mofeng.myshop.until.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author 作者
 * @since 2024-11-10
 */
@Tag(name = "卡密 相关接口", description = "卡密")
@RequiredArgsConstructor()
@RestController
@RequestMapping("/admin/carmine")
@PreAuthorize(value = "@permissionService.ROOT()")
public class CarmineAdminController {

    private final CarmineService carmineService;

    @PostMapping("")
    @Operation(summary = "卡密  新增")
    public R createCarmine(@RequestBody CarmineDto carmineDto) {
        return carmineService.createCarmine(carmineDto);
    }

    @DeleteMapping("")
    @Operation(summary = "卡密 批量删除")
    public R deleteCarmineList(@RequestParam("id") List<Long> ids) {
        return carmineService.deleteCarmineList(ids);
    }

    @GetMapping("/list/{page}/{size}")
    @Operation(summary = "卡密 分页查询")
    public R getPage(@PathVariable("page") int page,
                     @PathVariable("size") int size,
                     @RequestParam(value = "money", required = false) String money,
                     @RequestParam(value = "userId", required = false) Long userId,
                     @RequestParam(value = "used", required = false) Integer used,
                     @RequestParam(value = "startTime", required = false) String startTime,
                     @RequestParam(value = "endTime", required = false) String endTime) {
        CarmineQo carmineQo = new CarmineQo();
        carmineQo.setPage(page);
        carmineQo.setSize(size);
        carmineQo.setMoney(money);
        carmineQo.setUserId(userId);
        carmineQo.setUsed(used);
        carmineQo.setStart(startTime);
        carmineQo.setEnd(endTime);
        return carmineService.findPage(carmineQo);
    }

}